﻿using Sidvall.FileSystemManager.Net.Services.V1;
using System.Linq;

namespace Sidvall.FileSystemManager.Data
{
	public class CodeResult
	{
		public int ProcessedFolderCount { get; set; }
		public int ProcessedFileCount { get; set; }
		public int UpdatedFileCount { get; set; }

		private PathNameCollectionItem _PathNames;
		public PathNameCollectionItem PathNames
		{
			get
			{
				if (_PathNames == null)
					_PathNames = new PathNameCollectionItem();
				return _PathNames;
			}
		}

		public string GetDescription()
		{
			System.Text.StringBuilder sb;
			int count;

			sb = new System.Text.StringBuilder();
			if (this.ProcessedFolderCount > 0)
			{
				if (sb.Length > 0)
					sb.Append(System.Environment.NewLine);
				sb.Append("Processed folders: " + this.ProcessedFolderCount.ToString());
			}
			if (this.ProcessedFileCount > 0)
			{
				if (sb.Length > 0)
					sb.Append(System.Environment.NewLine);
				sb.Append("Processed files: " + this.ProcessedFileCount.ToString());
			}
			if (this.UpdatedFileCount > 0)
			{
				if (sb.Length > 0)
					sb.Append(System.Environment.NewLine);
				sb.Append("Updated files: " + this.UpdatedFileCount.ToString());
			}
			count = (from o in this.PathNames.Items
					 where o.IsFolder == false
					 select o).Count();
			if (count > 0)
			{
				if (sb.Length > 0)
					sb.Append(System.Environment.NewLine);
				sb.Append("Found files: " + count.ToString());
			}
			count = (from o in this.PathNames.Items
					 where o.IsFolder == true
					 select o).Count();
			if (count > 0)
			{
				if (sb.Length > 0)
					sb.Append(System.Environment.NewLine);
				sb.Append("Found folders: " + count.ToString());
			}

			return sb.ToString();
		}
	}
}
